import React from 'react'
import {Switch,Route,Redirect} from 'react-router-dom'

export default function RouterView(props) {
    let route=props.routes.filter(item=>item.component);
    let redirect=props.routes.filter(item=>item.redirect);
    return (
        <Switch>
            {
                route.map((item,index)=>{
                    return <Route key={index} path={item.path} render={(Info)=>{
                            return <item.component {...Info} routes={item.children}/>
                    }}/>
                })
            }
            {
                redirect.map((item,index)=>{
                    return <Redirect key={index} from={item.path} to={item.redirect}/>
                })
            }
        </Switch>
    )
}
